<?php
abstract class RCMSControllerBase {
	protected $app = null;
	protected $contents = array();

	public function __construct($app) {
		$this->app = $app;
	}

	protected function querySiteParameters($systemid, $subsysid, $systemlang) {
		$columns = array(
			'PARAM_ID',
			'PARAM_TEXT',
		);
		$whereClause = array(
			'SYSTEM_ID=:SYSTEM_ID',
			'SUBSYS_ID=:SUBSYS_ID',
			'SYSTEM_LANG=:SYSTEM_LANG',
			'PARAM_TYPE=\'00\'',
			'R_DEL_FLG =\'0\''
			);
			$orderClause = array('DISP_ORDER ASC');
			$params = array(
			'SYSTEM_ID'=>  $systemid,
			'SUBSYS_ID'=>  $subsysid,
			'SYSTEM_LANG'=>$systemlang,
			);
			$dao = $this->getApp()->getDbManager()->getDAO('RcmsTable');
			return $dao->fetchAllDataByTableName('RCMS_SITE_PARAM', $columns, $whereClause, $orderClause, $params);
	}
	protected function loadSiteParameters() {
		$results = $this->querySiteParameters(
		$this->getApp()->getSession()->get('SYSTEM_ID', '00'),
		$this->getApp()->getSession()->get('SUBSYS_ID', '00'),
		$this->getApp()->getSession()->get('SYSTEM_LANG', '*')
		);
		foreach ($results as $result) {
			$this->contents[$result['PARAM_ID']] = $result['PARAM_TEXT'];
		}
		$this->contents['site_baseurl'] = $this->getApp()->getRequest()->getBaseUrl();
	}
	public function run($action, $params) {
		$this->loadSiteParameters();
		$this->contents['menus'] = $this->getApp()->getMenus();
		$this->$action($params);
	}

	public function getApp() {
		return $this->app;
	}

	public function getContents() {
		return $this->contents;
	}
	public function setContent($name,$value) {
		$this->contents[$name] = $value;
	}
	public function getContent($name , $default='') {
		return isset($this->contents[$name]) ? $this->contents[$name] : $default;
	}
	protected  function isPost() {
		return $this->getApp()->getRequest()->isPost();
	}
}
?>